<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Aestate: aestate/work/sql/ExecuteSql.py Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Aestate
   &#160;<span id="projectnumber">1.0.5</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_374ee6e3281d8312d956f1f155302869.html">aestate</a></li><li class="navelem"><a class="el" href="dir_5abfa80149f37441c1f61fb6211d8f7d.html">work</a></li><li class="navelem"><a class="el" href="dir_28c055b2800b9e68511ac2cc19ed67ec.html">sql</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">ExecuteSql.py</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_execute_sql_8py.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"><a class="line" href="namespaceaestate_1_1work_1_1sql_1_1_execute_sql.html">    1</a></span>&#160;<span class="keyword">import</span> sys</div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160; </div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="keyword">from</span> <a class="code" href="namespaceaestate_1_1exception.html">aestate.exception</a> <span class="keyword">import</span> MySqlErrorTest</div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="keyword">from</span> <a class="code" href="namespaceaestate_1_1util_1_1_log.html">aestate.util.Log</a> <span class="keyword">import</span> ALog</div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="keyword">from</span> <a class="code" href="namespaceaestate_1_1opera_1_1_d_b_pool_1_1pooled__db.html">aestate.opera.DBPool.pooled_db</a> <span class="keyword">import</span> PooledDB</div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="keyword">from</span> <a class="code" href="namespaceaestate_1_1work_1_1_cache.html">aestate.work.Cache</a> <span class="keyword">import</span> SqlCacheManage, CacheStatus</div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160; </div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160; </div>
<div class="line"><a name="l00009"></a><span class="lineno"><a class="line" href="namespaceaestate_1_1work_1_1sql_1_1_execute_sql.html#a6a0a15248fd9b6c4471aa1c7832d71b3">    9</a></span>&#160;<span class="keyword">def </span><a class="code" href="namespaceaestate_1_1work_1_1sql_1_1_execute_sql.html#a6a0a15248fd9b6c4471aa1c7832d71b3">parse_kwa</a>(db, **kwargs):</div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;    <span class="stringliteral">&quot;&quot;&quot;</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="stringliteral">    解析并执行sql</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="stringliteral"></span> </div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="stringliteral">    :param db:db_util对象</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="stringliteral">    :param kwargs:包含所有参数:</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="stringliteral">            last_id:是否需要返回最后一行数据,默认False</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="stringliteral">            sql:处理过并加上%s的sql语句</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="stringliteral">            params:需要填充的字段</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="stringliteral">            print_sql:是否打印sql语句</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="stringliteral">            many:是否有多个</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="stringliteral">    &quot;&quot;&quot;</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160; </div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;    <span class="keywordflow">try</span>:</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;        cursor = db.cursor()</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;        <span class="comment"># 是否执行多条sql</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;        many_flay = <span class="stringliteral">&#39;many&#39;</span> <span class="keywordflow">in</span> kwargs.keys() <span class="keywordflow">and</span> kwargs[<span class="stringliteral">&#39;many&#39;</span>]</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;        <span class="keywordflow">if</span> <span class="stringliteral">&#39;print_sql&#39;</span> <span class="keywordflow">in</span> kwargs.keys() <span class="keywordflow">and</span> kwargs[<span class="stringliteral">&#39;print_sql&#39;</span>] <span class="keywordflow">is</span> <span class="keyword">True</span>:</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;            _l = sys._getframe().f_back.f_lineno</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;            msg = f<span class="stringliteral">&#39;{kwargs[&quot;sql&quot;]} - many=True&#39;</span> <span class="keywordflow">if</span> many_flay <span class="keywordflow">else</span> kwargs[<span class="stringliteral">&#39;sql&#39;</span>]</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;            ALog.log(obj=db, line=_l, task_name=<span class="stringliteral">&#39;ASQL&#39;</span>, msg=msg,</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;                     LogObject=kwargs[<span class="stringliteral">&#39;log_obj&#39;</span>] <span class="keywordflow">if</span> <span class="stringliteral">&#39;log_obj&#39;</span> <span class="keywordflow">in</span> kwargs.keys() <span class="keywordflow">else</span> <span class="keywordtype">None</span>)</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;        <span class="keywordflow">if</span> many_flay:</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;            cursor.executemany(kwargs[<span class="stringliteral">&#39;sql&#39;</span>],</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;                               tuple(kwargs[<span class="stringliteral">&#39;params&#39;</span>]) <span class="keywordflow">if</span> <span class="stringliteral">&#39;params&#39;</span> <span class="keywordflow">in</span> kwargs.keys() <span class="keywordflow">and</span> kwargs[<span class="stringliteral">&#39;params&#39;</span>] <span class="keywordflow">else</span> ())</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;        <span class="keywordflow">else</span>:</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;            cursor.execute(kwargs[<span class="stringliteral">&#39;sql&#39;</span>], tuple(kwargs[<span class="stringliteral">&#39;params&#39;</span>])</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;            <span class="keywordflow">if</span> <span class="stringliteral">&#39;params&#39;</span> <span class="keywordflow">in</span> kwargs.keys() <span class="keywordflow">and</span> kwargs[<span class="stringliteral">&#39;params&#39;</span>]</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;            <span class="keywordflow">else</span> ())</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;            <span class="comment"># try:</span></div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;            <span class="comment">#     CACodeLog.log(obj=db, line=_l, task_name=&#39;Print Sql&#39;, msg=cursor._executed)</span></div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;            <span class="comment"># except:</span></div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;            <span class="comment">#     CACodeLog.log(obj=db, line=_l, task_name=&#39;Print Sql&#39;, msg=msg)</span></div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;        <span class="keywordflow">return</span> cursor</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;    <span class="keywordflow">except</span> Exception <span class="keyword">as</span> e:</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        db.rollback()</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;        mysql_err = <a class="code" href="classaestate_1_1exception_1_1_my_sql_error_test.html">MySqlErrorTest</a>(e)</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;        mysql_err.ver()</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;        mysql_err.raise_exception()</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160; </div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160; </div>
<div class="line"><a name="l00050"></a><span class="lineno"><a class="line" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html">   50</a></span>&#160;<span class="keyword">class </span><a class="code" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html">Db_opera</a>(<a class="code" href="classaestate_1_1opera_1_1_d_b_pool_1_1pooled__db_1_1_pooled_d_b.html">PooledDB</a>):</div>
<div class="line"><a name="l00051"></a><span class="lineno"><a class="line" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#aba9a630a95683f961029692b32a22a97">   51</a></span>&#160;    <span class="keyword">def </span><a class="code" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#aba9a630a95683f961029692b32a22a97">__init__</a>(self, *args, **kwargs):</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;        <span class="keywordflow">if</span> <span class="stringliteral">&#39;POOL&#39;</span> <span class="keywordflow">not</span> <span class="keywordflow">in</span> kwargs <span class="keywordflow">or</span> kwargs[<span class="stringliteral">&#39;POOL&#39;</span>] <span class="keywordflow">is</span> <span class="keywordtype">None</span>:</div>
<div class="line"><a name="l00053"></a><span class="lineno"><a class="line" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#a9d475e1771249589ffb629d09216e6c2">   53</a></span>&#160;            self.<a class="code" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#a9d475e1771249589ffb629d09216e6c2">POOL</a> = self</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;        <span class="keywordflow">if</span> <span class="stringliteral">&#39;POOL&#39;</span> <span class="keywordflow">in</span> kwargs.keys():</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;            kwargs.pop(<span class="stringliteral">&#39;POOL&#39;</span>)</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160; </div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;        super(Db_opera, self).<a class="code" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#aba9a630a95683f961029692b32a22a97">__init__</a>(*args, **kwargs)</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160; </div>
<div class="line"><a name="l00059"></a><span class="lineno"><a class="line" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#af621539312f85b1fb61330704f011053">   59</a></span>&#160;    <span class="keyword">def </span><a class="code" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#af621539312f85b1fb61330704f011053">get_conn</a>(self):</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;        <span class="stringliteral">&quot;&quot;&quot;</span></div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;<span class="stringliteral">        获取数据库连接池</span></div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;<span class="stringliteral">        :return:</span></div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;<span class="stringliteral">        &quot;&quot;&quot;</span></div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;        conn = self.<a class="code" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#a9d475e1771249589ffb629d09216e6c2">POOL</a>.<a class="code" href="classaestate_1_1opera_1_1_d_b_pool_1_1pooled__db_1_1_pooled_d_b.html#a959ae7955f2dfae66ad44fd96e7b0717">connection</a>()</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;        <span class="keywordflow">return</span> conn</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160; </div>
<div class="line"><a name="l00067"></a><span class="lineno"><a class="line" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#afc77558cf0747f2325b05305c6ca01ad">   67</a></span>&#160;    <span class="keyword">def </span><a class="code" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#afc77558cf0747f2325b05305c6ca01ad">select</a>(self, **kwargs):</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;        <span class="stringliteral">&quot;&quot;&quot;</span></div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;<span class="stringliteral">        查找多个</span></div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;<span class="stringliteral">        :param kwargs:包含所有参数:</span></div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;<span class="stringliteral">            last_id:是否需要返回最后一行数据,默认False</span></div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;<span class="stringliteral">            sql:处理过并加上%s的sql语句</span></div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;<span class="stringliteral">            params:需要填充的字段</span></div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;<span class="stringliteral">            print_sql:是否打印sql语句</span></div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;<span class="stringliteral">        :return:</span></div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;<span class="stringliteral">        &quot;&quot;&quot;</span></div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;        db = self.<a class="code" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#af621539312f85b1fb61330704f011053">get_conn</a>()</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;        <span class="keywordflow">try</span>:</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;            cursor = db.cursor()</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;            sql = cursor.mogrify(kwargs[<span class="stringliteral">&#39;sql&#39;</span>], tuple(kwargs[<span class="stringliteral">&#39;params&#39;</span>]) <span class="keywordflow">if</span> <span class="stringliteral">&#39;params&#39;</span> <span class="keywordflow">in</span> kwargs.keys() <span class="keywordflow">and</span> kwargs[</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;                <span class="stringliteral">&#39;params&#39;</span>] <span class="keywordflow">else</span> ())</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;            scm = <a class="code" href="classaestate_1_1work_1_1_cache_1_1_sql_cache_manage.html">SqlCacheManage</a>()</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;            <span class="keywordflow">if</span> scm.status == CacheStatus.OPEN:</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;                <span class="keywordflow">if</span> sql <span class="keywordflow">in</span> scm:</div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;                    <span class="keywordflow">return</span> scm.get(sql).get_value()</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;            cursor = <a class="code" href="namespaceaestate_1_1work_1_1sql_1_1_execute_sql.html#a6a0a15248fd9b6c4471aa1c7832d71b3">parse_kwa</a>(db=db, **kwargs)</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;            <span class="comment"># 列名</span></div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;            col = cursor.description</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;            data = cursor.fetchall()</div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;            db.close()</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;            _result = []</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;            <span class="keywordflow">for</span> data_index, data_value <span class="keywordflow">in</span> enumerate(data):</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;                _messy = {}</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;                <span class="keywordflow">for</span> item_index, item_value <span class="keywordflow">in</span> enumerate(data_value):</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;                    _messy[col[item_index][0]] = item_value</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;                _result.append(_messy)</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;            <span class="keywordflow">if</span> scm.status == CacheStatus.OPEN:</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;                scm.set(sql=sql, value=_result, instance=kwargs[<span class="stringliteral">&#39;instance&#39;</span>] <span class="keywordflow">if</span> <span class="stringliteral">&#39;instance&#39;</span> <span class="keywordflow">in</span> kwargs.keys() <span class="keywordflow">else</span> <span class="keywordtype">None</span>)</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;            <span class="keywordflow">return</span> _result</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;        <span class="keywordflow">except</span> Exception <span class="keyword">as</span> e:</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;            db.rollback()</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;            ALog.log_error(</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;                msg=<span class="stringliteral">&#39;The pojo object has not been initialized yet, and no configuration items have been obtained&#39;</span>,</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;                obj=e, LogObject=kwargs[<span class="stringliteral">&#39;log_obj&#39;</span>] <span class="keywordflow">if</span> <span class="stringliteral">&#39;log_obj&#39;</span> <span class="keywordflow">in</span> kwargs.keys() <span class="keywordflow">else</span> <span class="keywordtype">None</span>, raise_exception=<span class="keyword">True</span>)</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;        <span class="keywordflow">finally</span>:</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;            db.close()</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160; </div>
<div class="line"><a name="l00108"></a><span class="lineno"><a class="line" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#a9287232ddbcabdb67c39f934aecc5774">  108</a></span>&#160;    <span class="keyword">def </span><a class="code" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#a9287232ddbcabdb67c39f934aecc5774">insert</a>(self, many=False, **kwargs):</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;        <span class="stringliteral">&quot;&quot;&quot;</span></div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;<span class="stringliteral">        执行插入语句</span></div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;<span class="stringliteral">        :param kwargs:包含所有参数:</span></div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;<span class="stringliteral">            last_id:是否需要返回最后一行数据,默认False</span></div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;<span class="stringliteral">            sql:处理过并加上%s的sql语句</span></div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;<span class="stringliteral">            params:需要填充的字段</span></div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;<span class="stringliteral">        :param many:是否为多行执行</span></div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;<span class="stringliteral">        &quot;&quot;&quot;</span></div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;        db = self.<a class="code" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#af621539312f85b1fb61330704f011053">get_conn</a>()</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;        <span class="keywordflow">try</span>:</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;            scm = <a class="code" href="classaestate_1_1work_1_1_cache_1_1_sql_cache_manage.html">SqlCacheManage</a>()</div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;            scm.remove_by_instance(kwargs[<span class="stringliteral">&#39;instance&#39;</span>].get_tb_name() <span class="keywordflow">if</span> <span class="stringliteral">&#39;instance&#39;</span> <span class="keywordflow">in</span> kwargs.keys() <span class="keywordflow">else</span> <span class="keywordtype">None</span>)</div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;            cursor = <a class="code" href="namespaceaestate_1_1work_1_1sql_1_1_execute_sql.html#a6a0a15248fd9b6c4471aa1c7832d71b3">parse_kwa</a>(db=db, many=many, **kwargs)</div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;            db.commit()</div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;            <span class="comment"># 受影响行数</span></div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;            rowcount = cursor.rowcount</div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;            <span class="comment"># 返回受影响行数</span></div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;            <span class="keywordflow">if</span> kwargs[<span class="stringliteral">&#39;last_id&#39;</span>]:</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;                <span class="keywordflow">return</span> rowcount, cursor.lastrowid</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;            <span class="keywordflow">else</span>:</div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;                <span class="keywordflow">return</span> rowcount</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;        <span class="keywordflow">except</span> Exception <span class="keyword">as</span> e:</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;            db.rollback()</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;            ALog.log_error(</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;                msg=<span class="stringliteral">&#39;The pojo object has not been initialized yet, and no configuration items have been obtained&#39;</span>,</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;                obj=e, LogObject=kwargs[<span class="stringliteral">&#39;log_obj&#39;</span>] <span class="keywordflow">if</span> <span class="stringliteral">&#39;log_obj&#39;</span> <span class="keywordflow">in</span> kwargs.keys() <span class="keywordflow">else</span> <span class="keywordtype">None</span>, raise_exception=<span class="keyword">True</span>)</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;        <span class="keywordflow">finally</span>:</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;            db.close()</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160; </div>
<div class="line"><a name="l00138"></a><span class="lineno"><a class="line" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#af488911adbdabd74a5f54c6c6b4f17d9">  138</a></span>&#160;    <span class="keyword">def </span><a class="code" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#af488911adbdabd74a5f54c6c6b4f17d9">update</a>(self, **kwargs):</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;        <span class="stringliteral">&quot;&quot;&quot;</span></div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;<span class="stringliteral">        执行更新语句</span></div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;<span class="stringliteral">        :param kwargs:包含所有参数:</span></div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;<span class="stringliteral">            last_id:是否需要返回最后一行数据,默认False</span></div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;<span class="stringliteral">            sql:处理过并加上%s的sql语句</span></div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;<span class="stringliteral">            params:需要填充的字段</span></div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;<span class="stringliteral">        &quot;&quot;&quot;</span></div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;        <span class="keywordflow">return</span> self.<a class="code" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#a9287232ddbcabdb67c39f934aecc5774">insert</a>(**kwargs)</div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160; </div>
<div class="line"><a name="l00148"></a><span class="lineno"><a class="line" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#a1366af70de61ad202ddd95d0c020ce05">  148</a></span>&#160;    <span class="keyword">def </span><a class="code" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#a1366af70de61ad202ddd95d0c020ce05">delete</a>(self, **kwargs):</div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;        <span class="stringliteral">&quot;&quot;&quot;</span></div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;<span class="stringliteral">        执行删除语句</span></div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;<span class="stringliteral">        :param kwargs:包含所有参数:</span></div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;<span class="stringliteral">            last_id:是否需要返回最后一行数据,默认False</span></div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;<span class="stringliteral">            sql:处理过并加上%s的sql语句</span></div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;<span class="stringliteral">            params:需要填充的字段</span></div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;<span class="stringliteral">        &quot;&quot;&quot;</span></div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;        self.<a class="code" href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#a9287232ddbcabdb67c39f934aecc5774">insert</a>(**kwargs)</div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="anamespaceaestate_1_1work_1_1sql_1_1_execute_sql_html_a6a0a15248fd9b6c4471aa1c7832d71b3"><div class="ttname"><a href="namespaceaestate_1_1work_1_1sql_1_1_execute_sql.html#a6a0a15248fd9b6c4471aa1c7832d71b3">aestate.work.sql.ExecuteSql.parse_kwa</a></div><div class="ttdeci">def parse_kwa(db, **kwargs)</div><div class="ttdef"><b>Definition:</b> <a href="_execute_sql_8py_source.html#l00009">ExecuteSql.py:9</a></div></div>
<div class="ttc" id="aclassaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera_html_af621539312f85b1fb61330704f011053"><div class="ttname"><a href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#af621539312f85b1fb61330704f011053">aestate.work.sql.ExecuteSql.Db_opera.get_conn</a></div><div class="ttdeci">def get_conn(self)</div><div class="ttdef"><b>Definition:</b> <a href="_execute_sql_8py_source.html#l00059">ExecuteSql.py:59</a></div></div>
<div class="ttc" id="anamespaceaestate_1_1opera_1_1_d_b_pool_1_1pooled__db_html"><div class="ttname"><a href="namespaceaestate_1_1opera_1_1_d_b_pool_1_1pooled__db.html">aestate.opera.DBPool.pooled_db</a></div><div class="ttdef"><b>Definition:</b> <a href="pooled__db_8py_source.html#l00001">pooled_db.py:1</a></div></div>
<div class="ttc" id="aclassaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera_html_afc77558cf0747f2325b05305c6ca01ad"><div class="ttname"><a href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#afc77558cf0747f2325b05305c6ca01ad">aestate.work.sql.ExecuteSql.Db_opera.select</a></div><div class="ttdeci">def select(self, **kwargs)</div><div class="ttdef"><b>Definition:</b> <a href="_execute_sql_8py_source.html#l00067">ExecuteSql.py:67</a></div></div>
<div class="ttc" id="aclassaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera_html"><div class="ttname"><a href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html">aestate.work.sql.ExecuteSql.Db_opera</a></div><div class="ttdef"><b>Definition:</b> <a href="_execute_sql_8py_source.html#l00050">ExecuteSql.py:50</a></div></div>
<div class="ttc" id="aclassaestate_1_1opera_1_1_d_b_pool_1_1pooled__db_1_1_pooled_d_b_html_a959ae7955f2dfae66ad44fd96e7b0717"><div class="ttname"><a href="classaestate_1_1opera_1_1_d_b_pool_1_1pooled__db_1_1_pooled_d_b.html#a959ae7955f2dfae66ad44fd96e7b0717">aestate.opera.DBPool.pooled_db.PooledDB.connection</a></div><div class="ttdeci">def connection(self, shareable=True)</div><div class="ttdef"><b>Definition:</b> <a href="pooled__db_8py_source.html#l00154">pooled_db.py:154</a></div></div>
<div class="ttc" id="anamespaceaestate_1_1work_1_1_cache_html"><div class="ttname"><a href="namespaceaestate_1_1work_1_1_cache.html">aestate.work.Cache</a></div><div class="ttdef"><b>Definition:</b> <a href="_cache_8py_source.html#l00001">Cache.py:1</a></div></div>
<div class="ttc" id="aclassaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera_html_a9287232ddbcabdb67c39f934aecc5774"><div class="ttname"><a href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#a9287232ddbcabdb67c39f934aecc5774">aestate.work.sql.ExecuteSql.Db_opera.insert</a></div><div class="ttdeci">def insert(self, many=False, **kwargs)</div><div class="ttdef"><b>Definition:</b> <a href="_execute_sql_8py_source.html#l00108">ExecuteSql.py:108</a></div></div>
<div class="ttc" id="aclassaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera_html_a1366af70de61ad202ddd95d0c020ce05"><div class="ttname"><a href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#a1366af70de61ad202ddd95d0c020ce05">aestate.work.sql.ExecuteSql.Db_opera.delete</a></div><div class="ttdeci">def delete(self, **kwargs)</div><div class="ttdef"><b>Definition:</b> <a href="_execute_sql_8py_source.html#l00148">ExecuteSql.py:148</a></div></div>
<div class="ttc" id="anamespaceaestate_1_1util_1_1_log_html"><div class="ttname"><a href="namespaceaestate_1_1util_1_1_log.html">aestate.util.Log</a></div><div class="ttdef"><b>Definition:</b> <a href="_log_8py_source.html#l00001">Log.py:1</a></div></div>
<div class="ttc" id="anamespaceaestate_1_1exception_html"><div class="ttname"><a href="namespaceaestate_1_1exception.html">aestate.exception</a></div><div class="ttdef"><b>Definition:</b> <a href="exception_2____init_____8py_source.html#l00001">__init__.py:1</a></div></div>
<div class="ttc" id="aclassaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera_html_aba9a630a95683f961029692b32a22a97"><div class="ttname"><a href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#aba9a630a95683f961029692b32a22a97">aestate.work.sql.ExecuteSql.Db_opera.__init__</a></div><div class="ttdeci">def __init__(self, *args, **kwargs)</div><div class="ttdef"><b>Definition:</b> <a href="_execute_sql_8py_source.html#l00051">ExecuteSql.py:51</a></div></div>
<div class="ttc" id="aclassaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera_html_af488911adbdabd74a5f54c6c6b4f17d9"><div class="ttname"><a href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#af488911adbdabd74a5f54c6c6b4f17d9">aestate.work.sql.ExecuteSql.Db_opera.update</a></div><div class="ttdeci">def update(self, **kwargs)</div><div class="ttdef"><b>Definition:</b> <a href="_execute_sql_8py_source.html#l00138">ExecuteSql.py:138</a></div></div>
<div class="ttc" id="aclassaestate_1_1opera_1_1_d_b_pool_1_1pooled__db_1_1_pooled_d_b_html"><div class="ttname"><a href="classaestate_1_1opera_1_1_d_b_pool_1_1pooled__db_1_1_pooled_d_b.html">aestate.opera.DBPool.pooled_db.PooledDB</a></div><div class="ttdef"><b>Definition:</b> <a href="pooled__db_8py_source.html#l00023">pooled_db.py:23</a></div></div>
<div class="ttc" id="aclassaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera_html_a9d475e1771249589ffb629d09216e6c2"><div class="ttname"><a href="classaestate_1_1work_1_1sql_1_1_execute_sql_1_1_db__opera.html#a9d475e1771249589ffb629d09216e6c2">aestate.work.sql.ExecuteSql.Db_opera.POOL</a></div><div class="ttdeci">POOL</div><div class="ttdef"><b>Definition:</b> <a href="_execute_sql_8py_source.html#l00053">ExecuteSql.py:53</a></div></div>
<div class="ttc" id="aclassaestate_1_1work_1_1_cache_1_1_sql_cache_manage_html"><div class="ttname"><a href="classaestate_1_1work_1_1_cache_1_1_sql_cache_manage.html">aestate.work.Cache.SqlCacheManage</a></div><div class="ttdef"><b>Definition:</b> <a href="_cache_8py_source.html#l00083">Cache.py:83</a></div></div>
<div class="ttc" id="aclassaestate_1_1exception_1_1_my_sql_error_test_html"><div class="ttname"><a href="classaestate_1_1exception_1_1_my_sql_error_test.html">aestate.exception.MySqlErrorTest</a></div><div class="ttdef"><b>Definition:</b> <a href="exception_2____init_____8py_source.html#l00080">__init__.py:80</a></div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>
